package com.example.demo.controller;

import com.example.demo.model.Blog;
import com.example.demo.model.User;
import com.example.demo.serivce.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 这里的 @RestController 相当于 @Controller + @ResponseBody
@RestController
@RequestMapping("/user")
public class UserController3 {
    @Autowired
    private UserService userService;

    @RequestMapping("insert5")
    public Integer insert5(Blog blog) {
        return userService.insert5(blog);
    }

    @RequestMapping("selectAll")
    public List<Blog> selectAll(Integer userId,Integer BlogId){
        return userService.selectAll(userId,BlogId);
    }

    @RequestMapping("/insert4")
    public Integer insert4(Blog blog){
        return userService.insert4(blog);
    }

    @RequestMapping("/getUserById")
    public List<Blog> getUserById(Integer userId) {
        return userService.getUserById(userId);
    }


    @RequestMapping("/getall")
    public List<Blog> getAll() {
        return userService.getAll();
    }

    @RequestMapping("/insert")
    public Integer insert(User user) {
        if (user == null || user.getUsername() == null
                || user.getPassword() == null
                || user.getUsername().equals("")
                || user.getPassword().equals("")
        ) { // 非法参数
            return 0;
        }
        return userService.insert(user);
    }

    @RequestMapping("/insert2")
    public Integer insert2(User user) {
        if (user == null || user.getUsername() == null
                || user.getPassword() == null
                || user.getUsername().equals("")
                || user.getPassword().equals("")
        ) { // 非法参数
            return 0;
        }
        userService.insert2(user);
        return user.getUserId();
    }
    @RequestMapping("/update")
    public Integer update(Integer userId, String password) {
        return userService.update(userId,password);
    }
    @RequestMapping("/delete")
    public Integer update(Integer userId) {
        return userService.delete(userId);
    }

    @RequestMapping("/getall2")
    public List<User> getall2(String sort){
        return userService.getall2(sort);
    }

    @RequestMapping("/getAll3")
    public List<User> getAll3(String username, String password){
        return userService.getAll3(username, password);
    }

    @RequestMapping("/findLike")
    public List<User> findLike(String username){
        return userService.findLike(username);
    }


    @RequestMapping("/testUpdate")
    public Integer testUpdate(User user) {
        return userService.testUpdate(user);
    }
    @RequestMapping("/deleteText")
    public Integer testDe(List<Integer> list){
        return userService.testDe(list);
    }
}
